home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / cpu / i8085 / i8085cpu.h < prev    next >
C/C++ Source or Header  |  1999-03-26  |  9KB  |  257 lines

  1. /*******************************************************
  2.  *
  3.  *      Portable (hopefully ;-) 8085A emulator
  4.  *
  5.  *      Written by J. Buchmueller for use with MAME
  6.  *
  7.  *        Partially based on Z80Em by Marcel De Kogel
  8.  *
  9.  *      CPU related macros
  10.  *
  11.  *******************************************************/
  12.  
  13. #define SF              0x80
  14. #define ZF              0x40
  15. #define YF              0x20
  16. #define HF              0x10
  17. #define XF              0x08
  18. #define VF              0x04
  19. #define NF              0x02
  20. #define CF              0x01
  21.  
  22. #define IM_SID          0x80
  23. #define IM_SOD          0x40
  24. #define IM_IEN          0x20
  25. #define IM_TRAP         0x10
  26. #define IM_INTR         0x08
  27. #define IM_RST75        0x04
  28. #define IM_RST65        0x02
  29. #define IM_RST55        0x01
  30.  
  31. #define ADDR_TRAP       0x0024
  32. #define ADDR_RST55      0x002c
  33. #define ADDR_RST65      0x0034
  34. #define ADDR_RST75      0x003c
  35. #define ADDR_INTR       0x0038
  36.  
  37. #define M_INR(R) ++R; I.AF.b.l=(I.AF.b.l&CF)|ZS[R]|((R==0x80)?VF:0)|((R&0x0F)?0:HF)
  38. #define M_DCR(R) I.AF.b.l=(I.AF.b.l&CF)|NF|((R==0x80)?VF:0)|((R&0x0F)?0:HF); I.AF.b.l|=ZS[--R]
  39. #define M_MVI(R) R=ARG()
  40.  
  41. #define M_ANA(R) I.AF.b.h&=R; I.AF.b.l=ZSP[I.AF.b.h]|HF
  42. #define M_ORA(R) I.AF.b.h|=R; I.AF.b.l=ZSP[I.AF.b.h]
  43. #define M_XRA(R) I.AF.b.h^=R; I.AF.b.l=ZSP[I.AF.b.h]
  44.  
  45. #define M_RLC {                                                 \
  46.     I.AF.b.h = (I.AF.b.h << 1) | (I.AF.b.h >> 7);                \
  47.     I.AF.b.l = (I.AF.b.l & ~(HF+NF+CF)) | (I.AF.b.h & CF);        \
  48. }
  49.  
  50. #define M_RRC {                                                 \
  51.     I.AF.b.l = (I.AF.b.l & ~(HF+NF+CF)) | (I.AF.b.h & CF);        \
  52.     I.AF.b.h = (I.AF.b.h >> 1) | (I.AF.b.h << 7);                \
  53. }
  54.  
  55. #define M_RAL {                                                 \
  56.     int c = I.AF.b.l&CF;                                        \
  57.     I.AF.b.l = (I.AF.b.l & ~(HF+NF+CF)) | (I.AF.b.h >> 7);        \
  58.     I.AF.b.h = (I.AF.b.h << 1) | c;                             \
  59. }
  60.  
  61. #define M_RAR {                                                 \
  62.     int c = (I.AF.b.l&CF) << 7;                                 \
  63.     I.AF.b.l = (I.AF.b.l & ~(HF+NF+CF)) | (I.AF.b.h & CF);        \
  64.     I.AF.b.h = (I.AF.b.h >> 1) | c;                             \
  65. }
  66.  
  67. #ifdef X86_ASM
  68. #define M_ADD(R)                                                \
  69.  asm (                                                            \
  70.  " addb %2,%0           \n"                                     \
  71.  " lahf                 \n"                                     \
  72.  " setob %%al           \n" /* al = 1 if overflow */            \
  73.  " shlb $2,%%al         \n" /* shift to P/V bit position */     \
  74.  " andb $0xd1,%%ah      \n" /* sign, zero, half carry, carry */ \
  75.  " orb %%ah,%%al        \n"                                     \
  76.  :"=g" (I.AF.b.h), "=a" (I.AF.b.l)                              \
  77.  :"r" (R), "0" (I.AF.b.h)                                       \
  78.  )
  79. #else
  80. #define M_ADD(R) {                                                \
  81. int q = I.AF.b.h+R;                                             \
  82.     I.AF.b.l=ZS[q&255]|((q>>8)&CF)|                             \
  83.         ((I.AF.b.h^q^R)&HF)|                                    \
  84.         (((R^I.AF.b.h^SF)&(R^q)&SF)>>5);                        \
  85.     I.AF.b.h=q;                                                 \
  86. }
  87. #endif
  88.  
  89. #ifdef X86_ASM
  90. #define M_ADC(R)                                                \
  91.  asm (                                                            \
  92.  " shrb $1,%%al         \n"                                     \
  93.  " adcb %2,%0           \n"                                     \
  94.  " lahf                 \n"                                     \
  95.  " setob %%al           \n" /* al = 1 if overflow */            \
  96.  " shlb $2,%%al         \n" /* shift to P/V bit position */     \
  97.  " andb $0xd1,%%ah      \n" /* sign, zero, half carry, carry */ \
  98.  " orb %%ah,%%al        \n" /* combine with P/V */              \
  99.  :"=g" (I.AF.b.h), "=a" (I.AF.b.l)                              \
  100.  :"r" (R), "a" (I.AF.b.l), "0" (I.AF.b.h)                       \
  101.  )
  102. #else
  103. #define M_ADC(R) {                                                \
  104.     int q = I.AF.b.h+R+(I.AF.b.l&CF);                            \
  105.     I.AF.b.l=ZS[q&255]|((q>>8)&CF)|                             \
  106.         ((I.AF.b.h^q^R)&HF)|                                    \
  107.         (((R^I.AF.b.h^SF)&(R^q)&SF)>>5);                        \
  108.     I.AF.b.h=q;                                                 \
  109. }
  110. #endif
  111.  
  112. #ifdef X86_ASM
  113. #define M_SUB(R)                                                \
  114.  asm (                                                            \
  115.  " subb %2,%0           \n"                                     \
  116.  " lahf                 \n"                                     \
  117.  " setob %%al           \n" /* al = 1 if overflow */            \
  118.  " shlb $2,%%al         \n" /* shift to P/V bit position */     \
  119.  " andb $0xd1,%%ah      \n" /* sign, zero, half carry, carry */ \
  120.  " orb $2,%%al          \n" /* set N flag */                    \
  121.  " orb %%ah,%%al        \n" /* combine with P/V */              \
  122.  :"=g" (I.AF.b.h), "=a" (I.AF.b.l)                              \
  123.  :"r" (R), "0" (I.AF.b.h)                                       \
  124.  )
  125. #else
  126. #define M_SUB(R) {                                                \
  127.     int q = I.AF.b.h-R;                                         \
  128.     I.AF.b.l=ZS[q&255]|((q>>8)&CF)|NF|                            \
  129.         ((I.AF.b.h^q^R)&HF)|                                    \
  130.         (((R^I.AF.b.h)&(I.AF.b.h^q)&SF)>>5);                    \
  131.     I.AF.b.h=q;                                                 \
  132. }
  133. #endif
  134.  
  135. #ifdef X86_ASM
  136. #define M_SBB(R)                                                \
  137.  asm (                                                            \
  138.  " shrb $1,%%al         \n"                                     \
  139.  " sbbb %2,%0           \n"                                     \
  140.  " lahf                 \n"                                     \
  141.  " setob %%al           \n" /* al = 1 if overflow */            \
  142.  " shlb $2,%%al         \n" /* shift to P/V bit position */     \
  143.  " andb $0xd1,%%ah      \n" /* sign, zero, half carry, carry */ \
  144.  " orb $2,%%al          \n" /* set N flag */                    \
  145.  " orb %%ah,%%al        \n" /* combine with P/V */              \
  146.  :"=g" (I.AF.b.h), "=a" (I.AF.b.l)                              \
  147.  :"r" (R), "a" (I.AF.b.l), "0" (I.AF.b.h)                       \
  148.  )
  149. #else
  150. #define M_SBB(R) {                                              \
  151.     int q = I.AF.b.h-R-(I.AF.b.l&CF);                            \
  152.     I.AF.b.l=ZS[q&255]|((q>>8)&CF)|NF|                            \
  153.         ((I.AF.b.h^q^R)&HF)|                                    \
  154.         (((R^I.AF.b.h)&(I.AF.b.h^q)&SF)>>5);                    \
  155.     I.AF.b.h=q;                                                 \
  156. }
  157. #endif
  158.  
  159. #ifdef X86_ASM
  160. #define M_CMP(R)                                                \
  161.  asm (                                                            \
  162.  " cmpb %2,%0          \n"                                      \
  163.  " lahf                \n"                                      \
  164.  " setob %%al          \n" /* al = 1 if overflow */             \
  165.  " shlb $2,%%al        \n" /* shift to P/V bit position */      \
  166.  " andb $0xd1,%%ah     \n" /* sign, zero, half carry, carry */  \
  167.  " orb $2,%%al         \n" /* set N flag */                     \
  168.  " orb %%ah,%%al       \n" /* combine with P/V */               \
  169.  :"=g" (I.AF.b.h), "=a" (I.AF.b.l)                              \
  170.  :"r" (R), "0" (I.AF.b.h)                                       \
  171.  )
  172. #else
  173. #define M_CMP(R) {                                              \
  174.     int q = I.AF.b.h-R;                                         \
  175.     I.AF.b.l=ZS[q&255]|((q>>8)&CF)|NF|                            \
  176.         ((I.AF.b.h^q^R)&HF)|                                    \
  177.         (((R^I.AF.b.h)&(I.AF.b.h^q)&SF)>>5);                    \
  178. }
  179. #endif
  180.  
  181. #define M_IN                                                    \
  182.     I.XX.d=ARG();                                                \
  183.     I.AF.b.h=cpu_readport(I.XX.d);
  184.  
  185. #define M_OUT                                                    \
  186.     I.XX.d=ARG();                                                \
  187.     cpu_writeport(I.XX.d,I.AF.b.h)
  188.  
  189. #ifdef    X86_ASM
  190. #define M_DAD(R)                                                \
  191.  asm (                                                            \
  192.  " andb $0xc4,%1        \n"                                     \
  193.  " addb %%al,%%cl       \n"                                     \
  194.  " adcb %%ah,%%ch       \n"                                     \
  195.  " lahf                 \n"                                     \
  196.  " andb $0x11,%%ah      \n"                                     \
  197.  " orb %%ah,%1          \n"                                     \
  198.  :"=c" (I.HL.d), "=g" (I.AF.b.l)                                \
  199.  :"0" (I.HL.d), "1" (I.AF.b.l), "a" (I.R.d)                     \
  200.  )
  201. #else
  202. #define M_DAD(R) {                                              \
  203.     int q = I.HL.d + I.R.d;                                     \
  204.     I.AF.b.l = ( I.AF.b.l & ~(HF+CF) ) |                        \
  205.         ( ((I.HL.d^q^I.R.d) >> 8) & HF ) |                        \
  206.         ( (q>>16) & CF );                                        \
  207.     I.HL.w.l = q;                                                \
  208. }
  209. #endif
  210.  
  211. #define M_PUSH(R) {                                             \
  212.     WM(--I.SP.w.l, I.R.b.h);                                    \
  213.     WM(--I.SP.w.l, I.R.b.l);                                    \
  214. }
  215.  
  216. #define M_POP(R) {                                                \
  217.     I.R.b.l = RM(I.SP.w.l++);                                    \
  218.     I.R.b.h = RM(I.SP.w.l++);                                    \
  219. }
  220.  
  221. #define M_RET(cc)                                                \
  222. {                                                                \
  223.     if (cc)                                                     \
  224.     {                                                            \
  225.         i8085_ICount -= 6;                                        \
  226.         M_POP(PC);                                                \
  227.         change_pc16(I.PC.d);                                    \
  228.     }                                                            \
  229. }
  230.  
  231. #define M_JMP(cc) {                                             \
  232.     if (cc) {                                                    \
  233.         I.PC.w.l = ARG16();                                     \
  234.         change_pc16(I.PC.d);                                    \
  235.     } else I.PC.w.l += 2;                                        \
  236. }
  237.  
  238. #define M_CALL(cc)                                                \
  239. {                                                                \
  240.     if (cc)                                                     \
  241.     {                                                            \
  242.         UINT16 a = ARG16();                                     \
  243.         i8085_ICount -= 7;                                        \
  244.         M_PUSH(PC);                                             \
  245.         I.PC.d = a;                                             \
  246.         change_pc16(I.PC.d);                                    \
  247.     } else I.PC.w.l += 2;                                        \
  248. }
  249.  
  250. #define M_RST(nn) {                                             \
  251.     M_PUSH(PC);                                                 \
  252.     I.PC.d = 8 * nn;                                            \
  253.     change_pc16(I.PC.d);                                        \
  254. }
  255.  
  256.  
  257.